import java.util.*;

class Node {
    public int[] position;

    public Node(int[] position) {
        this.position = position;
    }

    // for comparison
    @Override
    public boolean equals(Object obj) {
        if (obj == null) return false;
        if (obj instanceof int[]) return Arrays.equals(position, ((int[]) obj)); // in case obj is int[]
        int[] pos = ((Node) obj).position;
        return position[0] == pos[0] && position[1] == pos[1];
    }

    @Override
    public String toString() {
        return Arrays.toString(position);
    }

    public Node add(Node other) {
        return new Node(new int[]{position[0] + other.position[0], position[1] + other.position[1]});
    }
}


// Node subclass for A star algorithm
class AStarNode extends Node {
    public int g;
    public int h;
    public int f;
    public AStarNode parent;

    public AStarNode(int[] position, AStarNode parent, int g, int h) {
        super(position);
        this.parent = parent;
        this.g = g;
        this.h = h;
        this.f = g + h;
    }
}


// Node subclass for bfs algorithm
class bfsNode extends Node {
    public LinkedList<bfsNode> parents = new LinkedList<>();
    public boolean must = false;

    public bfsNode(int[] position) {
        super(position);
    }

    public bfsNode(int[] position, bfsNode parent) {
        super(position);
        parents.add(parent);
    }
}